package cn.zh.base.dto;

import cn.zh.base.util.MD5Utils;
import cn.zh.base.util.StrUtils;
import cn.zh.user.domain.User;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;

@Data
public class WechatBinderDto {
    @NotBlank(message = "电话不能为空！")
    private String phone;
    @NotBlank(message = "验证码不能为空！")
    private String verifyCode;
    @NotBlank(message = "accessToken不能为空！")
    private String accessToken;
    @NotBlank(message = "openId不能为空！")
    private String openId;
    @NotNull(message = "密码不能为空")
    // 密码
    private String password = "123456";

    public User getUser() {
        // 盐值
        String salt = StrUtils.getComplexRandomString(32);
        // 新鲜的撒盐密码
        String pwd = MD5Utils.encrypByMd5(salt + this.password);
        return User.builder()
                .createtime(new Date())
                .state(1)
                .salt(salt)
                .password(pwd)
                .phone(this.phone)
                .username(this.phone)
                .build();
    }

}
